

/*
 * Copyright (c) 2017,buu
 * All rights reserved.
 *
 * 文件名称：Boost_UDP.h
 * 文件标识：见软件框架协议
 * 摘  要：UDP读写类
 *
 * 当前版本：1.0
 * 作  者：geremy yang
 */

#ifndef BOOST_UDP_RECEIVE_H
#define BOOST_UDP_RECEIVE_H

#include "iostream"
#include "string.h"
#include "boost/algorithm/string.hpp"
#include "boost/regex.hpp"
#include "boost/asio.hpp"
#include "boost/thread.hpp"
#include "boost/lexical_cast.hpp"

using namespace boost;
using namespace std;
using boost::asio::ip::udp;
#define RECVSIZE 72
class Boost_UDP_Receive
{
public:
	// 构造函数，初始化ＵＤＰ
	Boost_UDP_Receive(boost::asio::io_service &io_service, string pcIP, int pcPort) : udp_sock(io_service, udp::endpoint(boost::asio::ip::address_v4::from_string(pcIP), pcPort))
	{
	}

	~Boost_UDP_Receive() // 析构函数，对象调用结束时关闭ＵＤＰ
	{
		udp_sock.close();
	}

	int receive_data(unsigned char buf[], int len)
	{
		udp::endpoint send_endpoint;
		int ret = udp_sock.receive_from(boost::asio::buffer(buf, len), send_endpoint); // 堵塞模式
		return ret;
	}

public:
	udp::socket udp_sock;
};

#endif
